package com.example.a2209_shop.adapter

import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.widget.ImageView
import android.widget.LinearLayout
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.a2209_shop.R
import com.example.base.entity.CateEntity

/**
 * 首页分类的适配器---展示的是二级中的电脑办公部分
 */
class TwoAdapter:BaseQuickAdapter<CateEntity,BaseViewHolder>(R.layout.item_two) {

    private var selectedId = 14
    override fun convert(holder: BaseViewHolder, item: CateEntity) {
        holder.setText(R.id.cate_tv,item.category_name)//文字设置
        /*val imageview = holder.getView<ImageView>(R.id.cate_iv)*/
        Glide.with(context).load(item.category_icon).into(holder.getView(R.id.cate_iv))
        holder.getView<LinearLayout>(R.id.two_ll).background = if(item.id==selectedId){
            ColorDrawable(Color.GREEN)
        }else null
    }
    //更新选中的item的id
    fun setId(id:Int){
        selectedId = id
        notifyDataSetChanged()
    }
}